PROJECT(useLib)
SET(TARGET useLib)

# 指定生成存放可执行文件的目录
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# 指定生成存放库文件的目录
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

CMAKE_MINIMUM_REQUIRED(VERSION 1.0)

AUX_SOURCE_DIRECTORY(src DIR_SRCS)

# 指定生成二进制
ADD_EXECUTABLE(${TARGET} ${DIR_SRCS})

# 指定头文件搜索路径, 可以改为设置环境变量CMAKE_INCLUDE_PATH=
#INCLUDE_DIRECTORIES(/tmp/demo/usr/include/demo)
FIND_PATH(demoHeader demo.h)
IF(demoHeader)
	INCLUDE_DIRECTORIES(${demoHeader})
ENDIF(demoHeader)

# 指定库文件搜索路径， 可以改为设置环境变量CMAKE_LIBRARY_PATH
#LINK_DIRECTORIES(/tmp/demo/usr/lib)

# 指定target信赖的共享库
#TARGET_LINK_LIBRARIES(${TARGET} demo)
FIND_LIBRARY(demoLib demo)
IF(demoLib)
	TARGET_LINK_LIBRARIES(${TARGET} ${demoLib})
ENDIF(demoLib)

# 指定二进制、动态库和静态库安装
INSTALL(TARGETS ${TARGET}
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION libstatic)

# 指定普通文件安装
#INSTALL(FILES COPYRIGHT README
#	DESTINATION share/doc/${TARGET})

# 指定非目标文件的可执行程序安装
#INSTALL(PROGRAMS rundemo.sh
#	DESTINATION bin)

# 指定目录的安装
#INSTALL(DIRECTORY doc/
#	DESTINATION share/doc/${TARGET})

# 测试cmake常用变量
MESSAGE("--- cmake常用变量 ---")
# 工程编译目录
MESSAGE("CMAKE_BINARY_DIR        : " ${CMAKE_BINARY_DIR})
MESSAGE("PROJECT_BINARY_DIR      : " ${PROJECT_BINARY_DIR})
MESSAGE("<projectname>_BINARY_DIR: " ${use_lib_BINARY_DIR})
# 工程顶层目录
MESSAGE("CMAKE_SOURCE_DIR        : " ${CMAKE_SOURCE_DIR})
MESSAGE("PROJECT_SOURCE_DIR      : " ${PROJECT_SOURCE_DIR})
MESSAGE("<projectname>_SOURCE_DIR: " ${use_lib_SOURCE_DIR})
# 当前处理的CMakeLists.txt所在的路径
MESSAGE("CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
# TARGET编译目录
MESSAGE("CMAKE_CURRENT_BINARY_DIR: " ${CMAKE_CURRENT_BINARY_DIR})
# 正在执行CMAkeLists.txt文件的完整路径
MESSAGE("CMAKE_CURRENT_LIST_FILE : " ${CMAKE_CURRENT_LIST_FILE})
# 当前所在的行
MESSAGE("CMAKE_CURRENT_LIST_LINE : " ${CMAKE_CURRENT_LIST_LINE})
# cmake模块所在的路径
MESSAGE("CMAKE_MODULE_PATH       : " ${CMAKE_MODULE_PATH})
# 存放可执行文件的目录
MESSAGE("ECUTABLE_OUTPUT_PATH    : " ${EXECUTABLE_OUTPUT_PATH})
# 存放库文件的目录
MESSAGE("LIBRARY_OUTPUT_PATH     : " ${LIBRARY_OUTPUT_PATH})
# 项目名称
MESSAGE("PROJECT_NAME            : " ${PROJECT_NAME})

MESSAGE("--- 系统信息 ---")
# 版本号
MESSAGE("CMAKE_MAJOR_VERSION     : " ${CMAKE_MAJOR_VERSION})
MESSAGE("CMAKE_MINOR_VERSION     : " ${CMAKE_MINOR_VERSION})
MESSAGE("CMAKE_PATCH_VERSION     : " ${CMAKE_PATCH_VERSION})
# 系统名称
MESSAGE("CMAKE_SYSTEM            : " ${CMAKE_SYSTEM})
# 不包含版本的系统名
MESSAGE("CMAKE_SYSTEM_NAME       : " ${CMAKE_SYSTEM_NAME})
# 系统版本
MESSAGE("CMAKE_SYSTEM_VERSION    : " ${CMAKE_SYSTEM_VERSION})
# 处理器名称
MESSAGE("CMAKE_SYSTEM_PROCESSOR  : " ${CMAKE_SYSTEM_PROCESSOR})
# 在所有的类 UNIX 平台为 TRUE
MESSAGE("UNIX                    : " ${UNIX})
# 在所有的 win32 平台为 TRUE
MESSAGE("WIN32                   : " ${WIN32})
